unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

const N = 800;

type
  TForm1 = class(TForm)
    Image1: TImage;
    Button1: TButton;
    Timer1: TTimer;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  Figure = class
    x, y, a : integer;
    procedure Draw; virtual;
    procedure Move(dx, dy : integer);
    procedure MakeRandom;
  end;

  Square = class(Figure)
    procedure Draw; override;
  end;
  Circle = class(Figure)
    procedure Draw; override;
  end;
  FilledSquare = class(Square)
    procedure Draw; override;
  end;

var
  Form1: TForm1;
  mas : array [0..N-1] of Figure;

implementation

{$R *.dfm}

{ Square }

procedure Square.Draw;
begin
  Form1.Image1.Canvas.Rectangle(x, y, x+a, y+a);
end;

procedure Figure.Draw;
begin

end;

procedure Figure.MakeRandom;
begin
    x := random(Form1.Image1.Width);
    y := random(Form1.Image1.Height);
    a := random(50);
end;

procedure Figure.Move(dx, dy: integer);
begin
  x := x + dx;
  y := y + dy;
end;

procedure TForm1.Button1Click(Sender: TObject);
var i : integer;
begin
  for i := 0 to N-1 do
  begin
    mas[i].MakeRandom;
    mas[i].Draw;
  end;
  Timer1.Enabled := True;
end;

procedure TForm1.FormCreate(Sender: TObject);
var i : integer;
begin
  randomize;
  for i := 0 to N-1 do
  begin
    if (i mod 2 = 0) then
      mas[i] := Circle.Create
    else
      mas[i] := FilledSquare.Create;
  end;
end;

{ Circle }

procedure Circle.Draw;
begin
  Form1.Image1.Canvas.Ellipse(x, y, x+a, y+a);
end;

{ FilledSquare }

procedure FilledSquare.Draw;
begin
  Form1.Image1.Canvas.Brush.Color := random(10000000);
  Form1.Image1.Canvas.Rectangle(x, y, x+a, y+a);
  Form1.Image1.Canvas.Brush.Color := clWhite;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var i : integer;
begin
  Image1.Canvas.Rectangle(0, 0, Image1.Width, Image1.Height);
  for i := 0 to N-1 do
  begin
    mas[i].Move(random(21)-10, random(21)-10);
    mas[i].Draw;
  end;
end;

end.
